#include "../scene/glutepage.h"
#include "../scene/program.h"
#include "../scene/mainpage.h"

using namespace cocos2d;

CCScene* GlutPageLayer01::scene()
{
	CCScene *scene = CCScene::node();
	GlutPageLayer01 *layer = GlutPageLayer01::node();
	scene->addChild(layer);
	return scene;
}
//-------------------------------------------------------------------
bool GlutPageLayer01::init()
{
	if(!CCLayer::init() )
	{
		return false;
	}

	setIsKeypadEnabled(true);

	CCSize size = CCDirector::sharedDirector()->getWinSize();
	CCSprite* pSprite = CCSprite::spriteWithFile("bg_setting.jpg");
	pSprite->setPosition(ccp(size.width/2,size.height/2));
	this->addChild(pSprite,0);

	CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("setbtn.plist");
	CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("gluteprog.plist");

	CCSprite* sprite_title = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("title_glute.png")); 

	//Glute 30
	CCSprite* sprite_glute30_01 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("glute30_01.png"));
	CCSprite* sprite_glute30_02 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("glute30_02.png"));
	sprite_glute30_02->setPosition(ccp(3,-3));
	//Glute 45
	CCSprite* sprite_glute45_01 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("glute45_01.png"));
	CCSprite* sprite_glute45_02 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("glute45_02.png"));
	sprite_glute45_02->setPosition(ccp(3,-3));	



	CCSprite* sprite_home01 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_home.png"));
	CCSprite* sprite_home02 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_home.png"));
	sprite_home02->setPosition(ccp(3,-3));

	CCSprite* sprite_back01 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_back.png"));
	CCSprite* sprite_back02 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_back.png"));
	sprite_back02->setPosition(ccp(3,-3));

	CCSprite* sprite_help01 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("help01.png"));
	CCSprite* sprite_help02 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("help02.png"));


	float sbw = size.width / 1024;
	float sbh = size.height / 768;


	sprite_title->setPosition(ccp((sbw*512.0f), size.height - (sbh *135.0f)));
	this->addChild(sprite_title,0);


	CCMenuItemSprite* item_glute30 = CCMenuItemSprite::itemFromNormalSprite(sprite_glute30_01,sprite_glute30_02,this,menu_selector(GlutPageLayer01::menuGlute30Callback));
	item_glute30->setPosition(ccp((sbw*515.0f), size.height - (sbh *340.0f)));

	CCMenuItemSprite* item_glute45 = CCMenuItemSprite::itemFromNormalSprite(sprite_glute45_01,sprite_glute45_02,this,menu_selector(GlutPageLayer01::menuGlute45Callback));
	item_glute45->setPosition(ccp((sbw*515.0f), size.height - (sbh *490.0f)));



	CCMenuItemSprite* item_home = CCMenuItemSprite::itemFromNormalSprite(sprite_home01,sprite_home02,this,menu_selector(GlutPageLayer01::menuHomeCallback));
	item_home->setPosition(ccp((sbw*960.0f), size.height - (sbh *700.0f)));

	CCMenuItemSprite* item_back = CCMenuItemSprite::itemFromNormalSprite(sprite_back01,sprite_back02,this,menu_selector(GlutPageLayer01::menuBackCallback));
	item_back->setPosition(ccp((sbw*860.0f), size.height - (sbh *700.0f)));


	CCMenuItemSprite* item_help = CCMenuItemSprite::itemFromNormalSprite(sprite_help01,sprite_help02,this,menu_selector(GlutPageLayer01::menuHelpCallback));
	item_help->setPosition(ccp((sbw*980.0f), size.height - (sbh *70.0f)));

	CCMenu* pmenu = CCMenu::menuWithItems(item_back,item_home,item_help,item_glute30,item_glute45, NULL);
	pmenu->setPosition(CCPointZero);

	addChild(pmenu);


	return true;
}

//-------------------------------------------------------------------
void GlutPageLayer01::menuGlute30Callback(cocos2d::CCObject *pSender)
{

}

//-------------------------------------------------------------------
void GlutPageLayer01::menuGlute45Callback(cocos2d::CCObject *pSender)
{

}

//-------------------------------------------------------------------
void GlutPageLayer01::menuHelpCallback(cocos2d::CCObject *pSender)
{

}
//-------------------------------------------------------------------
void GlutPageLayer01::menuHomeCallback(cocos2d::CCObject *pSender)
{
	CCScene* s = MainPageLayer01::scene();
	CCScene* pScene = CCTransitionCrossFade::transitionWithDuration(0.5f, s);
	CCDirector::sharedDirector()->replaceScene(pScene);
}
//-------------------------------------------------------------------
void GlutPageLayer01::menuBackCallback(cocos2d::CCObject *pSender)
{
	CCScene* s = ProgramLayer01::scene();
	CCScene* pScene = CCTransitionCrossFade::transitionWithDuration(0.5f, s);
    CCDirector::sharedDirector()->replaceScene(pScene);
}